﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NAGFwk.Model
{
    public class BaseObjectContext<T> where T : DbContext, new()
    {
        private readonly T _context;

        #region Singleton Pattern

        // Static members are lazily initialized.
        // .NET guarantees thread safety for static initialization.
        private static readonly BaseObjectContext<T> instance = new BaseObjectContext<T>();

        // Make the constructor private to hide it. 
        // This class adheres to the singleton pattern.
        private BaseObjectContext()
        {
            // Create the ObjectContext.
            _context = new T();
        }

        // Return the single instance of the ClientSessionManager type.
        public static BaseObjectContext<T> Instance
        {
            get
            {
                return instance;
            }
        }

        #endregion

        public T context
        {
            get
            {
                return _context;
            }
        }
    }
}